package com.wxy.demo.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;

/**
 * <p>
 * 自定义拦截器
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2023/1/3 10:41
 */
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ArrayList<String> excludes = new ArrayList<>();
        //swagger2
        excludes.add("/swagger-ui.html");
        excludes.add("/webjars/**");
        excludes.add("/swagger-resources/**");
        excludes.add("/v2/**");
        registry.addInterceptor(new HandlerInterceptor() {
            @Override
            public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
                return false;
            }
        }).addPathPatterns("/**").excludePathPatterns(excludes);
    }
}
